package com.arsn.myf.common.config;

import com.arsn.myf.common.handle.MetaHandler;
import com.baomidou.mybatisplus.core.config.GlobalConfig;
import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * mybatis-plus
 * @author zhongrj
 * @since 2022-07-21
 */
@Configuration
public class MybatisPlusConfig {

    @Autowired
    private MetaHandler metaHandler;

    /**
     * 分页配置,解决 total 为 0 的情况
     * @return
     */
    @Bean
    public PaginationInterceptor paginationInterceptor(){
        return new PaginationInterceptor();
    }


    /**
     * 设置 globalconfig,使可以自动写入BaseEntity中的字段数据
     * @return
     */
    @Bean
    public GlobalConfig globalConfig(){
        GlobalConfig config = new GlobalConfig();
        //设置MetaObjectHandler处理器
        config.setMetaObjectHandler(metaHandler);
        //返回
        return config;
    }

}
